package org.example.demo.controller;


import org.example.demo.config.R;
import org.example.demo.entity.Student;
import org.example.demo.entity.User;
import org.example.demo.service.StudentService;
import org.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lining
 * @since 2023-11-28
 */
@CrossOrigin
@RestController
@RequestMapping("/demo/user")
public class UserController {
    @Autowired
    private UserService userService;


    @PostMapping("user")
    public R add(@RequestBody User user){
        userService.save(user);
        return R.ok();
    }



    @PostMapping("upload")
    public R uploadOssFile(
            MultipartFile file) {
        //上传文件到oss,并得到文件的url
        String url = userService.uploadFileAvatar(file);
        return R.ok().data("url",url);
    }



    @PostMapping("uploadfilePath")
    public R uploadAlyVideo(MultipartFile file) {
        //返回上传视频的id
        String videoId = userService.uploadAlyVideo(file);
        return R.ok().data("videoId", videoId);
    }



    //跟后台的相关登陆
    @PostMapping("/login")
    public R login(){
        return R.ok().data("token","admin");
    }



    //跟后台的相关登陆账号和密码
    @GetMapping("/info")
    public R info(){
        return R.ok().data("roles","admin").data("name","admin").data("avatar","http://www.weixintouxiang.cn/weixin/20140607090832328.gif");
    }




}

